//
// Created by HP on 2024/2/18.
//

#include "LCD_thread.h"
#include "aurora_ui.h"
#include "aurora_wave.h"
#include "math.h"

ALIGN(RT_ALIGN_SIZE)
char lcd_thread_stack[LCD_THREAD_STACK_SIZE];
struct rt_thread lcd_thread;

EncoderKey_Driver encoderkey;
void LCD_thread(void *param){
    ui2foc_msg.cmd = IS_NONE;

    LCD_Driver lcd;            //lcd屏幕驱动
    Eflash_Driver eflash;      //外部flash驱动
    Aurora_Font font(&eflash);  //字体
    Aurora_UI ui;
    lcd.Init(3);
    lcd.fill(0xffff);
    ui.addEncoderKey_Driver(&encoderkey);
    ui.add_Driver(&lcd,&font);

    ui.boot_animation();  // 启动开机动画

//    Aurora_Label title_label;
//    title_label.set_font_driver(&font);
//    title_label.set_lcd_driver( &lcd);
//    title_label.set_font_size(Aurora_Font::font_size_big);
//    title_label.set_pos(90,0);
//    title_label.set_text("AuroraFOC");
//    title_label.show();

    while(true){
        if( foc2ui_msg.cmd != IS_NONE){
            ui.dealmsgEvent_from_FOC(&foc2ui_msg);
            foc2ui_msg.cmd = IS_NONE;
        }
        if( comm2ui_msg.cmd != IS_NONE) {
            ui.dealmsgEvent_from_COMM(&comm2ui_msg);
            comm2ui_msg.cmd = IS_NONE;
        }

        ui.dealKeyEvent();            //处理按键事务
        rt_thread_mdelay(1);
    }
}


//GPIO 外部中断
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
    //编码按键按下
    if( GPIO_Pin == EC_KEY_Pin || GPIO_Pin == EC_AR_Pin){
        encoderkey.EncoderKey_EXTI_Callback(GPIO_Pin);
    }
}